//  ViewController.swift
//  tabmenu
//
//  Created by YQ05 on 2018/4/17.
//  Copyright © 2018年 YQ05. All rights reserved.

//import Foundation
//import FWSegmentedControl
//import UIKit
//
//
///// segmentedControl字体大小
//let kSegmentTitleFont = 13.0
///// segmentedControl左边边距
//let kSegmentLeftEdge = 10
//
//class ViewController: UIViewController, UIScrollViewDelegate {
//
//    /// 是否点击了Segmented的滑块
//    var isClickedSegmented = false
//    /// Segmented的滑块起始页
//    var startPage = 0
//
////    let sectionTitles = ["关注", "游戏", "附近", "体育", "女神范", "运动啦啦", "歌舞", "吃鸡", "户外", "脱口秀"]
//
//    let imageTitles3 = ["叶子", "椰子啦", "叶紫"]
//
//
//
//    public lazy var segmentedControl7: FWSegmentedControl = {
//
//        let imageTitles3 = ["叶子", "椰子啦", "叶紫"]
//
//        let segmentedControl = FWSegmentedControl.segmentedWith(scType: SCType.textImages, scWidthStyle: SCWidthStyle.dynamicFixedSuper, sectionTitleArray: imageTitles3, sectionImageArray: nil, sectionSelectedImageArray: nil, frame: CGRect(x: 0, y: 300, width: Int(UIScreen.main.bounds.width), height: 40))
//
//        //        images2 as? [UIImage]
//        //        selectedImages2 as? [UIImage]
//
//        segmentedControl.scSelectionIndicatorStyle = .fullWidthStripe
//        segmentedControl.scSelectionIndicatorLocation = .down
//        segmentedControl.scImagePosition = .rightOfText
//        segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, CGFloat(kSegmentLeftEdge), 0, CGFloat(kSegmentLeftEdge))
//
//        segmentedControl.selectionIndicatorColor = UIColor.red
//        segmentedControl.selectionIndicatorHeight = 3
//
//        segmentedControl.verticalDividerEnabled = true
//        segmentedControl.verticalDividerColor = UIColor.lightGray
//        segmentedControl.verticalDividerWidth = 1.0
//
//        segmentedControl.textImageSpacing = 4
//
////        segmentedControl.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.gray, NSAttributedStringKey.font : UIFont.systemFont(ofSize: CGFloat(kSegmentTitleFont))]
////        segmentedControl.selectedTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.backgroundColor: UIColor.clear, NSAttributedStringKey.font: UIFont.systemFont(ofSize: CGFloat(kSegmentTitleFont))]
//
//        segmentedControl.autoresizingMask = .flexibleRightMargin
//
//        return segmentedControl
//    }()
//
//    lazy var scrollView: UIScrollView = {
//
//        let imageTitles3 = ["叶子", "椰子啦", "叶紫"]
//
//        let scrollView = UIScrollView(frame: CGRect(x: 0, y: self.segmentedControl7.frame.maxY, width: self.view.frame.width, height: self.view.frame.height-self.segmentedControl7.frame.maxY))
//        scrollView.backgroundColor = UIColor.clear
//        scrollView.delegate = self
//        scrollView.isPagingEnabled = true
//        scrollView.showsHorizontalScrollIndicator = false
//        scrollView.bounces = false
//        scrollView.contentSize = CGSize(width: self.view.bounds.width * CGFloat(imageTitles3.count), height: self.view.bounds.height-self.segmentedControl7.frame.maxY)
//        scrollView.scrollRectToVisible(CGRect(x: 0, y: 0, width: self.view.bounds.width, height: scrollView.frame.height), animated: false)
//        return scrollView
//    }()
//
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        //        self.view.backgroundColor = UIColor.lightGray
//        //        self.navigationItem.title = "FWSegmentedControl"
//        //        self.edgesForExtendedLayout = []
//
//        //self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "多级联动>", style: .plain, target: self, action: #selector(goNextVC))
//
//
//
//
//        self.view.addSubview(self.segmentedControl7)
//        self.view.addSubview(self.scrollView)
//
//        self.segmentedControl7.indexChangeBlock = { [weak self] index in
//            self?.isClickedSegmented = true
//            self?.scrollView.scrollRectToVisible(CGRect(x: (self?.view.bounds.width)! * CGFloat(index), y: 0, width: (self?.view.bounds.width)!, height: (self?.scrollView.frame.height)!), animated: true)
//        }
//
//        self.scrollView.addSubview(self.setupUIView(index: 0))
//        self.scrollView.addSubview(self.setupUIView(index: 1))
//        self.scrollView.addSubview(self.setupUIView(index: 2))
//    }
//}
//
//extension ViewController {
//
//    func setupUIView(index: Int) -> UILabel {
//
//        let label = UILabel(frame: CGRect(x: self.view.frame.width * CGFloat(index), y: 0, width: self.view.frame.width, height: self.scrollView.frame.height))
//        label.backgroundColor = UIColor(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1.0)
//        label.textColor = UIColor.white
//        label.text = self.imageTitles3[index]
//        label.textAlignment = .center
//        return label
//    }
//
//    func scrollViewDidScroll(_ scrollView: UIScrollView) {
//
//        if isClickedSegmented == false {
//            let pageWidth = scrollView.frame.width
//            let tmpPage = scrollView.contentOffset.x / pageWidth
//            let tmpPage2 = scrollView.contentOffset.x / pageWidth
//            let page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage
//            if startPage != Int(page) {
//                self.segmentedControl7.setSelectedSegmentIndex(index: Int(page), animated: true)
//                startPage = Int(page)
//            }
//        }
//    }
//
//    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
//        let pageWidth = scrollView.frame.width
//        let page = scrollView.contentOffset.x / pageWidth
//        self.isClickedSegmented = false
//        self.segmentedControl7.setSelectedSegmentIndex(index: Int(page), animated: true)
//    }
//
//
//}

//import UIKit
//import Moya
//import PageMenu
//import FWSegmentedControl
//
//class ViewController: UIViewController {
//    var pageMenu: CAPSPageMenu!
//    var controllers : [UIViewController] = []
//
//    @IBAction func showPageBtn(_ sender: UIButton) {
//        print("我被点击了")
//        //getshopList(id: 42)
//    }
//
//
//    func showMenu()  {
//        Category.request  { (cates) in
//
//            self.controllers = cates!.map{
//                let vc = self.storyboard?.instantiateViewController(withIdentifier: "SBID_NEWSLIST") as! NewsListController
//
//
//
//                vc.title = $0.title
//                vc.parentNavi = self.navigationController
//                vc.id = $0.id
//
//                return vc
//            }
//
//
//            let param : [CAPSPageMenuOption] = [
//                .menuItemSeparatorWidth(4.3),
//                .scrollMenuBackgroundColor(UIColor.white),
//                .viewBackgroundColor(UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)),
//                .bottomMenuHairlineColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 0.1)),
//                .selectionIndicatorColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),
//                .menuMargin(20.0),
//                .menuHeight(40.0),
//                .selectedMenuItemLabelColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),
//                .unselectedMenuItemLabelColor(UIColor(red: 40.0/255.0, green: 40.0/255.0, blue: 40.0/255.0, alpha: 1.0)),
//                .menuItemFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!),
//                .useMenuLikeSegmentedControl(false),
//                .menuItemSeparatorRoundEdges(true),
//                .selectionIndicatorHeight(2.0),
//                .menuItemSeparatorPercentageHeight(0.1)
//            ]
//
//            let frame = CGRect(x: 0, y: 20 + 70, width: self.view.frame.width, height: self.view.frame.height - 20 - 70)
//
//            self.pageMenu = CAPSPageMenu(viewControllers: self.controllers, frame: frame, pageMenuOptions: param)
//
//            self.view.addSubview(self.pageMenu.view)
//
//
//        }
//
//    }
//
//
//    //mark - 分段菜单
//
//    func showmanymenu() {
//
//       
//        print("2被显示了")
//    }
//
//
//
//
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)
//        //getshopList(id: 38)
//
//        //showMenu()
//        showmanymenu()
//    }
//
//    override func didReceiveMemoryWarning() {
//        super.didReceiveMemoryWarning()
//        // Dispose of any resources that can be recreated.
//    }
//
//
//}

import FWSegmentedControl
import Moya
import UIKit
import PageMenu
import Foundation


let segmentedControlHeight: CGFloat = 40.0
let segmentedControl2Height: CGFloat = 40.0

//var pageMenu: CAPSPageMenu!
var controllers : [UIViewController] = []


class ViewController: UIViewController, UIScrollViewDelegate {
    @IBAction func gonewspageBtn(_ sender: UIButton) {
    }
    
    @IBOutlet weak var testtitleLabel: UILabel!
    
    let sectionTitles = ["新闻", "购物"]

    let sectionTitles2 = ["教育專欄", "會員優惠", "活動回顧", "活動推介", "煮食無難度", "環保小先鋒", "美容專欄", "醫者父母心"]
    let sectionTitlesid2 = [15, 9, 11, 27, 21, 2, 26, 19]

    let sectionTitles3 = ["家居用品", "家用電器", "數碼配件", "服裝飾物", "精品", "美容護理", "課程", "運動用品"]
    
    var segmentedControlArray: [FWSegmentedControl] = []
    
    
    public lazy var segmentedControl: FWSegmentedControl = {
       let sectionTitles = ["新闻", "购物"]
        
       
  
        let segmentedControl = FWSegmentedControl.segmentedWith(scType: SCType.text, scWidthStyle: SCWidthStyle.dynamicFixedSuper, sectionTitleArray: sectionTitles, sectionImageArray: nil, sectionSelectedImageArray: nil, frame: CGRect(x: 0, y: 0 + 30, width: Int(UIScreen.main.bounds.width), height: Int(segmentedControlHeight) - 30 ))
        
        segmentedControl.scSelectionIndicatorStyle = .fullWidthStripe
        segmentedControl.scSelectionIndicatorLocation = .down
        segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, CGFloat(10), 0, CGFloat(10))
        
        segmentedControl.selectionIndicatorColor = UIColor.red
        segmentedControl.selectionIndicatorHeight = 3
        
        segmentedControl.verticalDividerEnabled = true
        segmentedControl.verticalDividerColor = UIColor.lightGray
        segmentedControl.verticalDividerWidth = 1.0
        
        //segmentedControl.scBorderType = .
        segmentedControl.segmentBorderColor = UIColor.lightGray
        segmentedControl.segmentBorderWidth = 1.0
        
        //        segmentedControl.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.gray, NSAttributedStringKey.font : UIFont.systemFont(ofSize: CGFloat(13.0))]
        //        segmentedControl.selectedTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.backgroundColor: UIColor.clear, NSAttributedStringKey.font: UIFont.systemFont(ofSize: CGFloat(13.0))]
        
        segmentedControl.autoresizingMask = .flexibleRightMargin
        
        return segmentedControl
    }()
    
    lazy var scrollView: UIScrollView = {
        let sectionTitles = ["index", "开发语言"]
        
        let scrollView = UIScrollView.init(frame: CGRect(x: 0, y: self.segmentedControl.frame.maxY, width: self.view.bounds.width, height: self.view.bounds.height - self.segmentedControl.frame.maxY))
        scrollView.tag = 0
        scrollView.backgroundColor = UIColor.clear
        scrollView.delegate = self
        scrollView.isPagingEnabled = true
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.bounces = false
        scrollView.contentSize = CGSize(width: self.view.bounds.width * CGFloat(sectionTitles.count), height: segmentedControl2Height)
        scrollView.scrollRectToVisible(CGRect(x: 0, y: 0, width: self.view.bounds.width, height: scrollView.frame.height), animated: false)
        return scrollView
    }()
    
    override func viewDidLoad() {
      
        super.viewDidLoad()
        
        
        
        self.view.backgroundColor = UIColor.lightGray
        self.edgesForExtendedLayout = []
        
        self.view.addSubview(self.segmentedControl)
        self.view.addSubview(self.scrollView)
        
        self.segmentedControl.indexChangeBlock = { [weak self] index in
            self?.scrollView.scrollRectToVisible(CGRect(x: (self?.view.bounds.width)! * CGFloat(index), y: 0, width: (self?.view.bounds.width)!, height: (self?.scrollView.frame.height)!), animated: true)
        }
        
        let segmentedControl2 = self.setupSegmentedControl(index: 0, sectionTitleArray: self.sectionTitles2)
        let segmentedControl3 = self.setupSegmentedControl(index: 1, sectionTitleArray: self.sectionTitles3)
        //let segmentedControl3 = self.newssetupSegmentedControl(index: 1, sectionTitleArray: self.sectionTitles3)
        
        self.segmentedControlArray.append(segmentedControl2)
        //self.segmentedControlArray.append(segmentedControl3)
        self.segmentedControlArray.append(segmentedControl3)
        
        self.scrollView.addSubview(segmentedControl2)
        
        self.scrollView.addSubview(segmentedControl3)
        
        
        //showNewsCatMenu()
//        getnewsarr { (ncate) in
//            let newsarr = ncate!
//            let sectionTitles5:[String] = newsarr
//            print("我收到数组的数据", sectionTitles5)
//        }
        
//        getproarr { (ncate) in
//            let proarr = ncate!
//            print("我收到数组的数据proarr", proarr)
//        }
        
         navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)
        
    }
}

extension ViewController {
    
    
    
    func setupSegmentedControl(index: Int, sectionTitleArray: [String]) -> FWSegmentedControl {
        
        let segmentedControl2 = FWSegmentedControl.segmentedWith(scType: SCType.text, scWidthStyle: SCWidthStyle.dynamicFixedSuper, sectionTitleArray: sectionTitleArray, sectionImageArray: nil, sectionSelectedImageArray: nil, frame: CGRect(x: Int(self.view.frame.width * CGFloat(index)), y: 0, width: Int(UIScreen.main.bounds.width), height: Int(segmentedControl2Height)))
        
        segmentedControl2.scSelectionIndicatorStyle = .fullWidthStripe
        segmentedControl2.scSelectionIndicatorLocation = .down
        segmentedControl2.segmentEdgeInset = UIEdgeInsetsMake(0, CGFloat(10), 0, CGFloat(10))
        
        segmentedControl2.selectionIndicatorColor = UIColor.red
        segmentedControl2.selectionIndicatorHeight = 3
        
        segmentedControl2.verticalDividerEnabled = true
        segmentedControl2.verticalDividerColor = UIColor.lightGray
        segmentedControl2.verticalDividerWidth = 1.0
        
        //        segmentedControl2.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.gray, NSAttributedStringKey.font : UIFont.systemFont(ofSize: CGFloat(13.0))]
        //        segmentedControl2.selectedTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.backgroundColor: UIColor.clear, NSAttributedStringKey.font: UIFont.systemFont(ofSize: CGFloat(13.0))]
        
        segmentedControl2.autoresizingMask = .flexibleRightMargin
        
        let scrollView2 = self.setupScrollView(index: index, sectionTitleArray: sectionTitleArray)
        self.scrollView.addSubview(scrollView2)
        
        segmentedControl2.indexChangeBlock = { [weak self] index in
            scrollView2.scrollRectToVisible(CGRect(x: (self?.view.bounds.width)! * CGFloat(index), y: 0, width: (self?.view.bounds.width)!, height: scrollView2.frame.height), animated: true)
        }
        
        return segmentedControl2
    }
    
    
    func newssetupSegmentedControl(index: Int, sectionTitleArray: [String]) -> FWSegmentedControl {
        
        let segmentedControl5 = FWSegmentedControl.segmentedWith(scType: SCType.text, scWidthStyle: SCWidthStyle.dynamicFixedSuper, sectionTitleArray: sectionTitleArray, sectionImageArray: nil, sectionSelectedImageArray: nil, frame: CGRect(x: Int(self.view.frame.width * CGFloat(index)), y: 0, width: Int(UIScreen.main.bounds.width), height: Int(segmentedControl2Height)))
        
        segmentedControl5.scSelectionIndicatorStyle = .fullWidthStripe
        segmentedControl5.scSelectionIndicatorLocation = .down
        segmentedControl5.segmentEdgeInset = UIEdgeInsetsMake(0, CGFloat(10), 0, CGFloat(10))
        
        segmentedControl5.selectionIndicatorColor = UIColor.red
        segmentedControl5.selectionIndicatorHeight = 3
        
        segmentedControl5.verticalDividerEnabled = true
        segmentedControl5.verticalDividerColor = UIColor.lightGray
        segmentedControl5.verticalDividerWidth = 1.0
        
        //        segmentedControl2.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.gray, NSAttributedStringKey.font : UIFont.systemFont(ofSize: CGFloat(13.0))]
        //        segmentedControl2.selectedTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.backgroundColor: UIColor.clear, NSAttributedStringKey.font: UIFont.systemFont(ofSize: CGFloat(13.0))]
        
        segmentedControl5.autoresizingMask = .flexibleRightMargin
        
        let scrollView5 = self.newssetupScrollView(index: index, sectionTitleArray: sectionTitleArray)
        self.scrollView.addSubview(scrollView5)
        
        segmentedControl5.indexChangeBlock = { [weak self] index in
            scrollView5.scrollRectToVisible(CGRect(x: (self?.view.bounds.width)! * CGFloat(index), y: 0, width: (self?.view.bounds.width)!, height: scrollView5.frame.height), animated: true)
        }
        
        return segmentedControl5
    }
    
    
    
    func newssetupScrollView(index: Int, sectionTitleArray: [String]) -> UIScrollView {
        
        let scrollView2 = UIScrollView.init(frame: CGRect(x: self.view.frame.width * CGFloat(index), y: segmentedControl2Height, width: self.view.bounds.width, height: self.view.bounds.height-self.segmentedControl.frame.maxY - segmentedControl2Height))
        scrollView2.tag = 1 + index
        scrollView2.backgroundColor = UIColor.clear
        scrollView2.delegate = self
        scrollView2.isPagingEnabled = true
        scrollView2.showsHorizontalScrollIndicator = false
        scrollView2.bounces = false
        scrollView2.contentSize = CGSize(width: self.view.bounds.width * CGFloat(sectionTitleArray.count), height: self.segmentedControl.frame.height)
        scrollView2.scrollRectToVisible(CGRect(x: 0, y: 0, width: self.view.bounds.width, height: scrollView2.frame.height), animated: false)
        
        
        //        var tmpIndex = -1

        
        var tmpIndex = -1
        for title in sectionTitleArray {
            tmpIndex += 1
            if tmpIndex == 0{
                scrollView2.addSubview(self.newssetupLabel(index: tmpIndex, title: "MGS"))
            }else{
                scrollView2.addSubview(self.setupLabel(index: tmpIndex, title: title))
            }
            
        }
        
        
        return scrollView2
    }
    
        
        
    
    
    
    
    func setupScrollView(index: Int, sectionTitleArray: [String]) -> UIScrollView {
        
        let scrollView2 = UIScrollView.init(frame: CGRect(x: self.view.frame.width * CGFloat(index), y: segmentedControl2Height, width: self.view.bounds.width, height: self.view.bounds.height-self.segmentedControl.frame.maxY - segmentedControl2Height))
        scrollView2.tag = 1 + index
        scrollView2.backgroundColor = UIColor.clear
        scrollView2.delegate = self
        scrollView2.isPagingEnabled = true
        scrollView2.showsHorizontalScrollIndicator = false
        scrollView2.bounces = false
        scrollView2.contentSize = CGSize(width: self.view.bounds.width * CGFloat(sectionTitleArray.count), height: self.segmentedControl.frame.height)
        scrollView2.scrollRectToVisible(CGRect(x: 0, y: 0, width: self.view.bounds.width, height: scrollView2.frame.height), animated: false)
        
//        var tmpIndex = -1
//        for title in sectionTitleArray {
//            tmpIndex += 1
//            scrollView2.addSubview(self.setupLabel(index: tmpIndex, title: title))
//        }
       
        /**setupLabel版本*/
//        var tmpIndex = -1
//        for title in sectionTitleArray {
//            tmpIndex += 1
//            if tmpIndex == 0{
//                 scrollView2.addSubview(self.setupLabel(index: tmpIndex, title: "title"))
//            }else{
//                 scrollView2.addSubview(self.setupLabel(index: tmpIndex, title: title))
//            }
//
//        }
        /**setupLabel版本*/
        
        
        var tmpIndex = 0
        for title in sectionTitleArray {
            
            scrollView2.addSubview(self.setupVC(firstIndex: index, secondIndex: tmpIndex, title: title))
            tmpIndex += 1
        }
        
        return scrollView2
    }
    
    
    func setupVC(firstIndex: Int, secondIndex: Int, title: String) -> UIView {
        
        if firstIndex == 0 {
            let newsVC = ViewController21()
            //let newsVC = NewsListThrController()
            //let newsVC = self.storyboard?.instantiateViewController(withIdentifier: "sbidtableviewcontroller22") as! TableViewController22
           //let newsVC = self.storyboard?.instantiateViewController(withIdentifier: "sbidNewslist") as! NewsCateListController
                
         //  let newsVC = self.storyboard?.instantiateViewController(withIdentifier: "sbid_NewsListThr") as! NewsListThrController
            
//            newsVC.indextitle = "VCindextitle:\(title)"
//            newsVC.getId = 26
            
            newsVC.view.frame = CGRect(x: self.view.frame.width * CGFloat(secondIndex), y: 0, width: self.view.frame.width, height: self.scrollView.frame.height)
//            newsVC.tableView.estimatedRowHeight = 100
//            newsVC.tableView.rowHeight = UITableViewAutomaticDimension
            

            newsVC.textLabel.text = "title:\(title)"
//            newsVC.setTitle(title: title)
            
            return newsVC.view

            //newsVC.textLabel.text = title
            
          
        } else {
            let shoppingVC = ViewController21()
            shoppingVC.view.frame = CGRect(x: self.view.frame.width * CGFloat(secondIndex), y: 0, width: self.view.frame.width, height: self.scrollView.frame.height)
            
         
            shoppingVC.textLabel.text = title
            
            return shoppingVC.view
        }
    }
    
    
    
    /**setupLabel版本*/
    func setupLabel(index: Int, title: String) -> UILabel {
        
        let label = UILabel(frame: CGRect(x: self.view.frame.width * CGFloat(index), y: 0, width: self.view.frame.width, height: self.scrollView.frame.height))
        label.backgroundColor = UIColor(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1.0)
        label.textColor = UIColor.white
        label.text = title
        label.textAlignment = .center
        return label
    }
    
    func newssetupLabel(index: Int, title: String) -> UILabel {
        
        let label = UILabel(frame: CGRect(x: self.view.frame.width * CGFloat(index), y: 0, width: self.view.frame.width, height: self.scrollView.frame.height))
        label.backgroundColor = UIColor.brown
        label.textColor = UIColor.white
        label.text = title
        label.textAlignment = .center
        testtitleLabel.text = "我给的数据"
        return label
    }
    

    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
        let pageWidth = scrollView.frame.width
        let page = scrollView.contentOffset.x / pageWidth
        
        if scrollView.tag == 0 {
            self.segmentedControl.setSelectedSegmentIndex(index: Int(page), animated: true)
        } else {
            let segmentedControl = segmentedControlArray[scrollView.tag-1]
            segmentedControl.setSelectedSegmentIndex(index: Int(page), animated: true)
        }
    }
}



